#! /bin/bash

INTERFACE=stlink
TRANSPORT=swd
TARGET=stm32l4x
HEXFILE=build/coros-test.hex
ELFFILE=build/coros-test.out
ADAPTER_SPEED=8000

ADAPTER_SPEED_CMD=-c 'adapter speed ${ADAPTER_SPEED}'

killall -9 openocd
openocd -f "interface/${INTERFACE}.cfg" -c "transport select ${TRANSPORT}" -f "target/${TARGET}.cfg" -c "program ${HEXFILE} verify reset exit"
(
    openocd -f "interface/${INTERFACE}.cfg" -c "transport select ${TRANSPORT}" -c "adapter speed ${ADAPTER_SPEED}" -f "target/${TARGET}.cfg" &> /dev/null &
)

gdb-multiarch ${ELFFILE} -ex "target remote localhost:3333" -ex "tui enable" -ex "tui reg general" -ex "focus cmd"
